<?php
/**
 * 后台基层控制器
 * User: Administrator
 * Date: 2018\10\9 0009
 * Time: 14:11
 */

namespace app\admin\controller;


use app\Lib\Api\Menu\getTopMenu;
use app\Lib\Model\Login\DoLogin;
use app\Lib\TopClient;
use think\Controller;
use think\Url;

class Base extends Controller
{
    protected $login_uid;
    protected $userInfo;
    public function _initialize()
    {
//        try{
            $login =(new DoLogin());
            //验证登录
            if(!$login->isLogin()){
                $this->error('请先登录',Url::build('UserLogin/login'));
            }
            //判断是否属于多重登录
            if(!$login->validateLogin()){
                //清除这台设备的登录标识
                $login->webOutLogin();
                $this->error('您的账号已在别处登录',Url::build('UserLogin/login'));
            }
            //请求头部菜单
//            $topMenu = [];
            $topMenu = new getTopMenu();
            $topMenu = (new TopClient($topMenu))->getSuccessData();
            if(empty($topMenu) || !is_array($topMenu)){
                $topMenu = [];
            }
//            dump($topMenu);
            $this->login_uid = session('login_uid');
            $this->login_uid = empty($this->login_uid)?cookie(md5('userInfo')):$this->login_uid;
            $this->userInfo = session('userInfo');
            $this->userInfo = empty($this->userInfo)?cookie(md5('userInfoBase')):$this->userInfo;
            $userInfo = $this->userInfo;
            $this->assign('topMenu',$topMenu);
            $this->assign('userInfo',$userInfo);
//        }catch (\Exception $exception){
//            echo  $exception->getMessage();
//        }
    }
}